<?php
	require_once 'header.php';
?>
<div class="box_title">Server status</div>
		<div class="box_body p10">
		<ul>
				<li><strong>IP:</strong> <?php echo configParser::getData('ip'); ?></li>
				<li><strong>Port:</strong> <?php echo configParser::getData('port'); ?></li>
				<?php
					$info = new OTS_ServerInfo( configParser::getData('ip'), configParser::getData('port') );
					$status = @$info->status();
					
					if( !$status )
					{
						echo '<li><strong>Status:</strong> <strong style="color: red">Offline</strong></li>';
					}
					else
					{
						echo '<li><strong>Status:</strong> <strong style="color: green">Online</strong></li>';
						
						$up = $status->getUptime();
						if( $up >= 86400 )
						{
							$days = floor( $up / 86400 );
							$hours = floor(( $up-$days*86400 ) / 3600);
							$minutes = floor( ($up-$days*86400-$hours*3600) / 60 );
							$seconds = $up-$days*86400-$hours*3600-$minutes*60;
							
							$formattedString = $days . ' d ' . $hours . ' h ' . $minutes . ' m ' . $seconds . ' s';
						}
						elseif( $up >= 3600 and $up > 86400 )
						{
							$hours = floor(($up / 3600));
							$minutes = floor(($up-$hours*3600)/60);
							$seconds = ($up-$hours*3600-$minutes*60);
							
							$formattedString =  $hours . ' h ' . $minutes . ' m ' . $seconds . ' s';
						}
						elseif( $up >= 60 and $up < 3600 )
						{
							$minutes = floor($up / 60);
							$seconds = $up - $minutes*60;
							
							$formattedString = $minutes . ' m ' . $seconds . ' s';
						}
						else
						{
							$formattedString = $up . ' s';
						}
							
						echo '<li><strong>Uptime:</strong> '.$formattedString.'</li>';
						echo '<li><strong>Players:</strong> '.$status->onlinePlayers . ' / ' . $status->maxPlayers.'</li>';
						echo '<li><a href="?m=playersonline" style="font-weight: bold;">Show players online</a></li>';
					}
				?>
		</ul>
</div>

<div class="box_bottom"></div>